package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

import java.util.ArrayList;

public class OtherStudentDao implements BaseStudentDao{
    //1.创建学生数组
    private  static ArrayList<Student> arrayList= new ArrayList<>();

    static{
        Student stu1 = new Student("heima001","张三",18,"1999-11-11");
        Student stu2 = new Student("heima002","李四",19,"2000-12-12");
        arrayList.add(stu1);
        arrayList.add(stu2);

    }
    //添加学生
    public boolean addStudent(Student stu) {
        arrayList.add(stu);
        return true;
        }
    //查找学生
    public Student[] findAllStudent() {
        Student[] arr = new Student[arrayList.size()];
        for (int i = 0; i < arr.length; i++) {
            arr[i]=arrayList.get(i);
        }
        return arr;

    }
    //删除学生
    public boolean deleteStudentById(String delId) {
        boolean flag= false;
        for (int i = 0; i < arrayList.size(); i++) {
            if (arrayList.get(i).getId().equals(delId)){
                arrayList.remove(i);
                flag=true;
            }
        }
        return true;
    }

    //修改学生
    public boolean updateStudent(String updateId, Student newStu) {
        boolean flag=false;
        for (int i = 0; i < arrayList.size(); i++) {
            if (arrayList.get(i).getId().equals(updateId)){
                arrayList.set(i,newStu);
                flag=true;
            }
        }
        return flag;
    }
}
